document.write('<script src="helper.js"></script>');
function testSticky(){
	testAddSticky();
	testRemoveSticky();
	testUnRemoveSticky();
	testGetSticky();
	testEditSticky();
	testGetHistory();
	testMoveSticky();
	testViewHistory();
	
}
function helperAddSticky(){
	 var info = {
		"category" : "story",
                "state_id" : 1,
                "priority_id": 1,
                "release_id": 1,
                "note": "This is a test",
                "title": "Title here",
                "color": "#FFFFFF",
                "severity_id" : 1,
                "defect_state_id" : 0
        }
	var ret = get("stickyApi.php","addSticky",info);
	return ret.sticky_id;
}
function helperGetSticky(stickyId){
	var info = { "stickyId" : stickyId }
	var ret = get("stickyApi.php", "getSticky", info);
	return ret;
}
function testGetSticky(){
	write("Testing getSticky");
	var sticky_id = helperAddSticky();
	var ret = helperGetSticky(sticky_id);
	write(ret.sticky_id == sticky_id);
}
function testEditSticky(){
	var sticky_id = helperAddSticky();
	var ret = helperGetSticky(sticky_id);
	var last_updated = ret.last_updated;
	write("Testing editSticky");
	var info = {
		"stickyId" : sticky_id,
		"category" : "story",
		"state_id" : 1,
		"priority_id": 1,
		"release_id": 1,
		"note": "22222",
		"title": "22222",
		"color": "#FFFFFF",
		"severity_id" : 1,
		"defect_state_id" : 0,
		"last_updated" : last_updated
	}
	var sticky = helperGetSticky(sticky_id);
	write(ret.success == true);
}
function testAddSticky(){
	write("Testing Add Sticky");
	var info = {
		"state_id" : 1,
		"priority_id": 1,
		"release_id": 1,
		"note": "This is a test",
		"title": "Title here",
		"color": "#FFFFFF",
		"severity_id" : 1,
		"defect_state_id" : 1
	}
	var ret = get("stickyApi.php","addSticky",info);
	if(ret.hasOwnProperty("errors")){
		write(ret.errors.hasOwnProperty("category"));
	}else write(false);
	info["category"] = "story2";
	var ret = get("stickyApi.php","addSticky",info);
	if(ret.hasOwnProperty("errors")){
		write(ret.errors.hasOwnProperty("category"));
	}else write(false);
	info["category"] = "story";
	info["state_id"] = 1000;
	var ret = get("stickyApi.php","addSticky",info);
	if(ret.hasOwnProperty("errors")){
		write(ret.errors.hasOwnProperty("state_id"));
	}else write(false);
	info["state_id"] = 1;
	info["release_id"] = 1000;
	var ret = get("stickyApi.php","addSticky",info);
	if(ret.hasOwnProperty("errors")){
		write(ret.errors.hasOwnProperty("release_id"));
	}else write(false);
	info["release_id"] = 1;
	var ret = get("stickyApi.php","addSticky",info);
	if(ret.hasOwnProperty("sticky_id")){
		write(ret.sticky_id >= 0);
	}else write(false);
	info["category"] = "defect";
	var ret = get("stickyApi.php","addSticky",info);
	if(ret.hasOwnProperty("sticky_id")){
		write(ret.sticky_id >= 0);
	}else write(false);
}

function testMoveSticky(){
	write("Testing moveSticky");
	var sticky_id = helperAddSticky();
	var sticky_id2 = helperAddSticky();
	var sticky_id3 = helperAddSticky();
	var info = {"position" : "to",
			"stickyId" : sticky_id,
			"relativeTo" : 3}
	var ret = get("stickyApi.php","moveSticky",info);
	write(ret.success);
}


function testRemoveSticky(){

	write("Testing Remove Sticky");
	var stickyId = "1201";
	info = { "stickyId" : stickyId};
	var ret = get("stickyApi.php","removeSticky",info);
	write(ret.success);

}

function testUnRemoveSticky(){

	write("Testing unRemove Sticky");
	var stickyId = "1201";
	info = { "stickyId" : stickyId};
	var ret = get("stickyApi.php","unRemoveSticky",info);
	write(ret.success);

}

function testViewHistory(){

	write("Testing viewHistory");
	var stickyID = "1237";
	info = { "stickyId" : stickyID};
	var ret = get("stickyApi.php","viewHistory",info);
	write(ret.success);
}

function testGetHistory(){
     var send = {"state" : 1};
     var dfs = get("stickyApi.php","getId",send);
 }





